<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="​    CMSIS DSP库中定点复数FFT的输入需要使用Q31或者Q15的数，其中Q31的数它实际的范围是(-1, 1)。我先用python造了一些复数，做FFT；然后再在stm32上调用DSP库做FFT，并将两者结果对比。 ​    直接上python代码： 1234567891011121314151617181920212223import numpy as npif __name__">
<meta property="og:type" content="article">
<meta property="og:title" content="CMSIS DSP库的复数定点FFT使用">
<meta property="og:url" content="http://example.com/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="​    CMSIS DSP库中定点复数FFT的输入需要使用Q31或者Q15的数，其中Q31的数它实际的范围是(-1, 1)。我先用python造了一些复数，做FFT；然后再在stm32上调用DSP库做FFT，并将两者结果对比。 ​    直接上python代码： 1234567891011121314151617181920212223import numpy as npif __name__">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152339.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152608.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153251.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153427.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408161947.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162118.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162242.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162426.png">
<meta property="og:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162514.png">
<meta property="article:published_time" content="2021-04-08T10:55:36.000Z">
<meta property="article:modified_time" content="2021-04-08T10:55:36.000Z">
<meta property="article:author" content="xudonglei">
<meta property="article:tag" content="信号处理">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152339.png">

<link rel="canonical" href="http://example.com/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>CMSIS DSP库的复数定点FFT使用 | 学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          CMSIS DSP库的复数定点FFT使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-08 18:55:36" itemprop="dateCreated datePublished" datetime="2021-04-08T18:55:36+08:00">2021-04-08</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/" class="post-meta-item leancloud_visitors" data-flag-title="CMSIS DSP库的复数定点FFT使用" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>​    CMSIS DSP库中定点复数FFT的输入需要使用Q31或者Q15的数，其中Q31的数它实际的范围是(-1, 1)。我先用python造了一些复数，做FFT；然后再在stm32上调用DSP库做FFT，并将两者结果对比。</p>
<p>​    直接上python代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    <span class="comment"># print(np.hamming(32))</span></span><br><span class="line">    <span class="comment"># x0 = np.random.random_sample((32,))</span></span><br><span class="line">    <span class="comment"># print(x0)</span></span><br><span class="line">    input_float = np.array([<span class="number">0.33688039</span>+<span class="number">0.27576947j</span>, <span class="number">0.99445967</span>+<span class="number">0.76294948j</span>,</span><br><span class="line">                            <span class="number">0.70402479</span>+<span class="number">0.07054292j</span>, <span class="number">0.44225181</span>+<span class="number">0.24120408j</span>,</span><br><span class="line">                            <span class="number">0.48560569</span>+<span class="number">0.12177725j</span>, <span class="number">0.18824296</span>+<span class="number">0.87400103j</span>,</span><br><span class="line">                            <span class="number">0.38203619</span>+<span class="number">0.13971502j</span>, <span class="number">0.21115924</span>+<span class="number">0.16845203j</span>,</span><br><span class="line">                            <span class="number">0.86836398</span>+<span class="number">0.44339537j</span>, <span class="number">0.91344222</span>+<span class="number">0.18359897j</span>,</span><br><span class="line">                            <span class="number">0.66934949</span>+<span class="number">0.953202j</span>,   <span class="number">0.98336128</span>+<span class="number">0.51880677j</span>,</span><br><span class="line">                            <span class="number">0.7314163</span>+<span class="number">0.41706149j</span>,  <span class="number">0.61245894</span>+<span class="number">0.02790013j</span>,</span><br><span class="line">                            <span class="number">0.20736128</span>+<span class="number">0.37723832j</span>, <span class="number">0.27917189</span>+<span class="number">0.33977751j</span>,</span><br><span class="line">                            <span class="number">0.79783386</span>+<span class="number">0.55812144j</span>, <span class="number">0.51681</span>+<span class="number">0.59290067j</span>,</span><br><span class="line">                            <span class="number">0.33205087</span>+<span class="number">0.87387007j</span>, <span class="number">0.19170072</span>+<span class="number">0.18220524j</span>,</span><br><span class="line">                            <span class="number">0.39737357</span>+<span class="number">0.69744759j</span>, <span class="number">0.28801394</span>+<span class="number">0.82422595j</span>,</span><br><span class="line">                            <span class="number">0.27648721</span>+<span class="number">0.49734381j</span>, <span class="number">0.63294795</span>+<span class="number">0.50805464j</span>,</span><br><span class="line">                            <span class="number">0.67525571</span>+<span class="number">0.15635329j</span>, <span class="number">0.44887195</span>+<span class="number">0.33571562j</span>,</span><br><span class="line">                            <span class="number">0.71634485</span>+<span class="number">0.82814263j</span>, <span class="number">0.49399417</span>+<span class="number">0.34142172j</span>,</span><br><span class="line">                            <span class="number">0.39951166</span>+<span class="number">0.56482186j</span>, <span class="number">0.51141589</span>+<span class="number">0.57559398j</span>,</span><br><span class="line">                            <span class="number">0.39054342</span>+<span class="number">0.41560708j</span>, <span class="number">0.65810208</span>+<span class="number">0.55645494j</span>])</span><br><span class="line">    fft_result = np.fft.fft(input_float * np.hamming(<span class="number">32</span>), <span class="number">32</span>)</span><br><span class="line">    print(fft_result)</span><br></pre></td></tr></table></figure>
<p>​    部分关键C代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Q15_ONE    (32768) </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Q16_ONE    (65536)   </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">float32_t</span> hamming_window[<span class="number">64</span>] =</span><br><span class="line">&#123;</span><br><span class="line">	<span class="number">0.08000000</span>, <span class="number">0.08000000</span>, <span class="number">0.08941623</span>, <span class="number">0.08941623</span>, <span class="number">0.11727941</span>, <span class="number">0.11727941</span>, <span class="number">0.16244882</span>, <span class="number">0.16244882</span>, </span><br><span class="line">	<span class="number">0.22307522</span>, <span class="number">0.22307522</span>, <span class="number">0.29667656</span>, <span class="number">0.29667656</span>, <span class="number">0.38023958</span>, <span class="number">0.38023958</span>, <span class="number">0.47034322</span>, <span class="number">0.47034322</span>, </span><br><span class="line">	<span class="number">0.56329862</span>, <span class="number">0.56329862</span>, <span class="number">0.65530016</span>, <span class="number">0.65530016</span>, <span class="number">0.74258131</span>, <span class="number">0.74258131</span>, <span class="number">0.82156875</span>, <span class="number">0.82156875</span>, </span><br><span class="line">	<span class="number">0.88902874</span>, <span class="number">0.88902874</span>, <span class="number">0.94219944</span>, <span class="number">0.94219944</span>, <span class="number">0.97890406</span>, <span class="number">0.97890406</span>, <span class="number">0.99763989</span>, <span class="number">0.99763989</span>, </span><br><span class="line">	<span class="number">0.99763989</span>, <span class="number">0.99763989</span>, <span class="number">0.97890406</span>, <span class="number">0.97890406</span>, <span class="number">0.94219944</span>, <span class="number">0.94219944</span>, <span class="number">0.88902874</span>, <span class="number">0.88902874</span>, </span><br><span class="line">	<span class="number">0.82156875</span>, <span class="number">0.82156875</span>, <span class="number">0.74258131</span>, <span class="number">0.74258131</span>, <span class="number">0.65530016</span>, <span class="number">0.65530016</span>, <span class="number">0.56329862</span>, <span class="number">0.56329862</span>, </span><br><span class="line">	<span class="number">0.47034322</span>, <span class="number">0.47034322</span>, <span class="number">0.38023958</span>, <span class="number">0.38023958</span>, <span class="number">0.29667656</span>, <span class="number">0.29667656</span>, <span class="number">0.22307522</span>, <span class="number">0.22307522</span>, </span><br><span class="line">	<span class="number">0.16244882</span>, <span class="number">0.16244882</span>, <span class="number">0.11727941</span>, <span class="number">0.11727941</span>, <span class="number">0.08941623</span>, <span class="number">0.08941623</span>, <span class="number">0.08000000</span>, <span class="number">0.08000000</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">uint16_t</span> hamming_window_Q16[<span class="number">64</span>];</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//实部,虚部,实部,虚部...</span></span><br><span class="line"><span class="keyword">float32_t</span> input_float[<span class="number">32</span>*<span class="number">2</span>] = </span><br><span class="line">&#123;</span><br><span class="line">     <span class="number">0.33688039</span>, <span class="number">0.27576947</span>, <span class="number">0.99445967</span>, <span class="number">0.76294948</span>,</span><br><span class="line">     <span class="number">0.70402479</span>, <span class="number">0.07054292</span>, <span class="number">0.44225181</span>, <span class="number">0.24120408</span>,</span><br><span class="line">     <span class="number">0.48560569</span>, <span class="number">0.12177725</span>, <span class="number">0.18824296</span>, <span class="number">0.87400103</span>,</span><br><span class="line">     <span class="number">0.38203619</span>, <span class="number">0.13971502</span>, <span class="number">0.21115924</span>, <span class="number">0.16845203</span>,</span><br><span class="line">     <span class="number">0.86836398</span>, <span class="number">0.44339537</span>, <span class="number">0.91344222</span>, <span class="number">0.18359897</span>,</span><br><span class="line">     <span class="number">0.66934949</span>, <span class="number">0.953202</span>,   <span class="number">0.98336128</span>, <span class="number">0.51880677</span>,</span><br><span class="line">     <span class="number">0.7314163</span>, <span class="number">0.41706149</span>,  <span class="number">0.61245894</span>, <span class="number">0.02790013</span>,</span><br><span class="line">     <span class="number">0.20736128</span>, <span class="number">0.37723832</span>, <span class="number">0.27917189</span>, <span class="number">0.33977751</span>,</span><br><span class="line">     <span class="number">0.79783386</span>, <span class="number">0.55812144</span>, <span class="number">0.51681</span>, <span class="number">0.59290067</span>,</span><br><span class="line">     <span class="number">0.33205087</span>, <span class="number">0.87387007</span>, <span class="number">0.19170072</span>, <span class="number">0.18220524</span>,</span><br><span class="line">     <span class="number">0.39737357</span>, <span class="number">0.69744759</span>, <span class="number">0.28801394</span>, <span class="number">0.82422595</span>,</span><br><span class="line">     <span class="number">0.27648721</span>, <span class="number">0.49734381</span>, <span class="number">0.63294795</span>, <span class="number">0.50805464</span>,</span><br><span class="line">     <span class="number">0.67525571</span>, <span class="number">0.15635329</span>, <span class="number">0.44887195</span>, <span class="number">0.33571562</span>,</span><br><span class="line">     <span class="number">0.71634485</span>, <span class="number">0.82814263</span>, <span class="number">0.49399417</span>, <span class="number">0.34142172</span>,</span><br><span class="line">     <span class="number">0.39951166</span>, <span class="number">0.56482186</span>, <span class="number">0.51141589</span>, <span class="number">0.57559398</span>,</span><br><span class="line">     <span class="number">0.39054342</span>, <span class="number">0.41560708</span>, <span class="number">0.65810208</span>, <span class="number">0.55645494</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">int16_t</span> input_Q15[<span class="number">32</span>*<span class="number">2</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int32_t</span> mul_Q31[<span class="number">64</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(i=<span class="number">0</span>; i&lt;<span class="number">64</span>; i++)</span><br><span class="line">&#123;</span><br><span class="line">	hamming_window_Q16[i] = round(hamming_window[i] * Q16_ONE);</span><br><span class="line">	input_Q15[i] = round(input_float[i] * Q15_ONE);</span><br><span class="line">	mul_Q31[i] = hamming_window_Q16[i] * input_Q15[i];</span><br><span class="line">&#125;</span><br><span class="line">arm_cfft_q31(&amp;arm_cfft_sR_q31_len32, mul_Q31, <span class="number">0</span>, <span class="number">1</span>);</span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">32</span>; i++)</span><br><span class="line">&#123;</span><br><span class="line">       <span class="built_in">printf</span>(<span class="string">&quot;%4d: %.8f, %.8f\r\n&quot;</span>, i, mul_Q31[<span class="number">2</span>*i]/<span class="number">67108864.0</span> , mul_Q31[<span class="number">2</span>*i+<span class="number">1</span>]/<span class="number">67108864.0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    对比两者运算的结果，误差基本很小：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152339.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152608.png" style="zoom:40%;">

<p>​    下面对C中的代码做简单介绍：</p>
<ul>
<li><p>代码中汉明窗的值固定小于1的,<strong>并且固定是正数</strong>，所以直接转换成Q16的值，注意转换后的值要是uint16_t类型，不然有可能放不下原来的数据。（因为int16_t的范围是-32768~32767）</p>
</li>
<li><p>做完fft之后的结果对一致性的时候需要除以67108864(即2的26次方)，原因如下所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153251.png" style="zoom:87%;">

</li>
</ul>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153427.png" style="zoom:80%;">

<p>​    当做32点FFT的时候，输入格式为1.31，输出格式应该为6.26，即输出为Q26的数据。</p>
<p>​    <strong>情形二</strong>：当输入的数据不是(-1, 1)之间的值，而是int16_t类型的值时，怎么处理？我们这边可以把它当成是Q15的值，最终和python那端对一致性的时候，把C工程中输出结果也转成Q15的。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408161947.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162118.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162242.png" style="zoom:80%;">

<p>最终对比两者运算的结果：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162426.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162514.png" style="zoom:47%;">

<p>​    这边除以2048(即2的11次方)的原因是，32点FFT输出的是Q26格式，但是最终和python对一致性的是用Q15格式，所以需要除以2的11次方。</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E4%BF%A1%E5%8F%B7%E5%A4%84%E7%90%86/" rel="tag"># 信号处理</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/" rel="prev" title="STM32使用RTC时钟及闹钟功能">
      <i class="fa fa-chevron-left"></i> STM32使用RTC时钟及闹钟功能
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/" rel="next" title="STM32L475待机模式闹钟唤醒方式">
      STM32L475待机模式闹钟唤醒方式 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
